//管理用户数据相关
import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getAdminInfo } from '../api/pcUser.js'

export const createAdminStore = defineStore('admin', () => {
    //1.定义管理用户数据的state
    const adminInfo = ref({})
    //2.定义获取接口数据的action函数
    const setAdminInfo = async (adminInfoData) => {
        sessionStorage.setItem('adminInfo', JSON.stringify(adminInfoData))
    }

    const getAdminInfo = () => {
        return getSessionStorageObj('userInfo')
      }
    
      // 3.定义重置用户信息的方法
      const resetAdminInfo = () => {
        userInfo.value = {}
        sessionStorage.removeItem('userInfo')
      }

    //3.以对象的格式把state和action  return
    return {
        adminInfo,
        setAdminInfo,
        getAdminInfo,
        resetAdminInfo
    }
}, {
    //用于持久化
    persist: true
})